function smallestNumber(nums) {
    function compar(a, b) {
        let val1 = Number(String(a) + String(b))
        let val2 = Number(String(b) + String(a))
        return val1 - val2
    }
    nums.sort((a, b) => a - b)
    return nums.join('')
}
let nums = [3, 30, 34, 5, 9]
console.log(smallestNumber(nums));